<script setup>
    import {ref} from "vue"
    const todeTask = ref('')

    // 子传父，新增待办任务
    const emit = defineEmits()
    const startAdd = () => {
        // 非空校验
        if (!todeTask.value) {
            return window.alert("待办任务不能为空")
        }
        // 携带参数通知父组件进行新增
        emit("add", todeTask.value)
        // 清空输入框
        todeTask.value = ""
    }
</script>
<template>
    <header class="header">
        <h1>⽐特⼈的记事本</h1>
        <input class="new-todo" placeholder="What needs to be finished?" autofocus 
        v-model.trim="todeTask"
        @keydown.enter="startAdd"
        />
    </header>
</template>
